package com.abvnet.project.water.sewage.controller;

import com.abvnet.framework.aspectj.lang.annotation.Log;
import com.abvnet.framework.aspectj.lang.enums.BusinessType;
import com.abvnet.framework.web.controller.BaseController;
import com.abvnet.framework.web.domain.AjaxResult;
import com.abvnet.framework.web.page.TableDataInfo;
import com.abvnet.project.water.sewage.domain.SewageIndex;
import com.abvnet.project.water.sewage.service.ISewageIndexService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 污水指标信息操作处理
 * 
 * @author duj
 * @date 2019-07-02
 */
@Controller
@RequestMapping("/sewage/sewageIndex")
public class SewageIndexController extends BaseController {
    private String prefix = "sewage/sewageIndex";
	
	@Autowired
	private ISewageIndexService sewageIndexService;
	
	@RequiresPermissions("sewage:sewageIndex:list")
	@GetMapping()
	public String sewageIndex()
	{
	    return prefix + "/sewageIndex";
	}
	
	/**
	 * 查询污水指标列表
	 */
	@RequiresPermissions("sewage:sewageIndex:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(SewageIndex sewageIndex) {
		startPage();
        List<SewageIndex> list = sewageIndexService.selectSewageIndexList(sewageIndex);
		return getDataTable(list);
	}
	
	/**
	 * 新增污水指标
	 */
	@GetMapping("/add")
	public String add() {
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存污水指标
	 */
	@RequiresPermissions("sewage:sewageIndex:add")
	@Log(title = "污水指标", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(SewageIndex sewageIndex) {
		return toAjax(sewageIndexService.insertSewageIndex(sewageIndex));
	}

	/**
	 * 修改污水指标
	 */
	@GetMapping("/edit/{indexId}")
	public String edit(@PathVariable("indexId") Long indexId, ModelMap mmap) {
		SewageIndex sewageIndex = sewageIndexService.selectSewageIndexById(indexId);
		mmap.put("sewageIndex", sewageIndex);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存污水指标
	 */
	@RequiresPermissions("sewage:sewageIndex:edit")
	@Log(title = "污水指标", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(SewageIndex sewageIndex) {
		return toAjax(sewageIndexService.updateSewageIndex(sewageIndex));
	}
	
	/**
	 * 删除污水指标
	 */
	@RequiresPermissions("sewage:sewageIndex:remove")
	@Log(title = "污水指标", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids) {
		return toAjax(sewageIndexService.deleteSewageIndexByIds(ids));
	}
	
}
